home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 2.5 KB | 77 lines | [TEXT/KAHL] |
- /* PSDbits.c */
- /* This module contains the routines for bitmap operations */
- /* Copyright 1992, Gary D. McGath */
-
- pascal void psdBitsProc(BitMap *srcBits, Rect *srcRect, Rect *dstRect,
- short mode, RgnHandle maskRgn);
-
- extern int thePSFile; /* ID of file to output to */
-
-
-
- /* In this version, the only mode supported is copy. Most others
- are problematical, since PostScript doesn't allow logical combinations
- with an existing raster.
- We support only 1-bit bitmaps here; Pixmaps are ignored (left as an
- exercise for the reader). */
- pascal void psdBitsProc(BitMap *srcBits, Rect *srcRect, Rect *dstRect,
- short mode, RgnHandle maskRgn)
- {
- int pixelWidth, pixelDepth;
- Ptr dataPtr;
- int byteWidth;
- register int i, j;
-
- if (srcBits->rowBytes & 0X8000) /* is it a pixmap? */
- return; /* then give up */
- if (srcRect->left != srcBits->bounds.left)
- return; /* we don't handle this case properly yet */
-
- pixelWidth = srcRect->right - srcRect->left;
- pixelDepth = srcRect->bottom - srcRect->top;
- byteWidth = (pixelWidth + 7) / 8;
-
- OutputString("/SV save def /ims ",thePSFile); /* avoid accumulating garbage */
- OutputNum(byteWidth,thePSFile);
- OutputString("string def\r",thePSFile); /* buffer 1 scan line wide */
- /* First need to scale and position to target rect */
- OutputNum(dstRect->left, thePSFile);
- OutputNum(dstRect->top, thePSFile);
- OutputString("translate\r",thePSFile);
-
- OutputNum(dstRect->right - dstRect->left, thePSFile);
- OutputNum(dstRect->bottom - dstRect->top, thePSFile);
- OutputString("scale\r",thePSFile);
-
-
- /* Output "w h 1 [w 0 0 h 0 0 ] {currentfile ims readhexstring pop} image" */
-
- OutputNum(pixelWidth, thePSFile);
- OutputNum(pixelDepth, thePSFile);
- OutputString("1 [",thePSFile);
- OutputNum(pixelWidth, thePSFile); /* width */
- OutputString("0 0 ", thePSFile);
- OutputNum(pixelDepth, thePSFile);
- OutputString("0 0 ] {currentfile ims readhexstring pop} image\r",thePSFile);
-
- /* Now output the image as hex data. As a further cheap trick, we
- assume that the left edge of srcRect matches the left edge of the
- BitMap rectangle; in real life this isn't a valid assumption,
- and bit shifting will be needed. */
- dataPtr = srcBits->baseAddr;
- for (i = 0; i < pixelDepth; i++) {
- for (j = 0; j < byteWidth; j++) {
- OutputHex(~*dataPtr++,thePSFile);
- if ((j & 0X7F) == 0X7F)
- OutputChar('\r', thePSFile); /* avoid excessively long lines */
- }
- if (byteWidth & 1) /* if odd, have to skip a byte at end of row */
- dataPtr++;
- OutputChar('\r', thePSFile);
- }
- OutputString("SV restore\r",thePSFile);
- }
-
-
-
-